package config

import (
	"context"
	"fmt"

	"github.com/redis/go-redis/v9"
)

type Redis struct {
	Address  string `yaml:"address"`
	Port     int    `yaml:"port"`
	Password string `yaml:"password"`
	Db       int    `yaml:"db"`
}

func (r *Redis) InitRedisClient() (*redis.Client, error) {

	client := redis.NewClient(&redis.Options{
		Addr: fmt.Sprintf("%s:%d", r.Address, r.Port),
		DB:   r.Db,
	})
	if _, err := client.Ping(context.Background()).Result(); err != nil {
		return nil, err
	}

	return client, nil
}
